/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *    2011 year
 *    Author: Michael Khromov aka MikeDM (Mike D'Morto)
 *    E-Mail: mikedmorto@gmail.com
 */

#include "mw.h"
#include "ui_mw.h"
#include <QUrl>
#include <QMessageBox>


MW::MW(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MW)
{
    ui->setupUi(this);

    // load config
    this->loadConfig();
    this->Shost.port=500;
    this->saveConfig();


    connect(&this->clientx,SIGNAL(done(int,QVariant)),this,SLOT(slotDone(int,QVariant)));
    connect(&this->clientx,SIGNAL(failed(int,int,QString)),this,SLOT(slotFail(int,int,QString)));

    /*
    QUrl url("http://host/RPC2");
    this->clientx.setHost(url.host(),777,url.path());
    this->clientx.setUserAgent("Qt");

    int id = this->clientx.request("stargazer.info");
    */
}

MW::~MW()
{
    delete ui;
}

void MW::loadConfig(){
    QSettings cfg(QSettings::IniFormat,QSettings::UserScope,"stg-team","Qstgconfig");
    this->Shost.port=cfg.value("main/port",8080).toInt();
    qDebug()<<"hh-"<<this->Shost.port;
    this->Shost.host=cfg.value("main/host","localhost").toString();
}

void MW::saveConfig(){
    QSettings cfg(QSettings::IniFormat,QSettings::UserScope,"stg-team","Qstgconfig");
    cfg.beginGroup("main");
    cfg.setValue("port",this->Shost.port);
    cfg.setValue("host",this->Shost.host);
    cfg.endGroup();

}


void MW::slotDone(int id, QVariant variant){
    qDebug()<<"done";
    QMap<QString,QVariant> map(variant.toMap());
    qDebug()<<"map = "<<map;

}

void MW::slotFail(int id, int errcode, QString errstr){
    qDebug()<<"fail is - "<<errstr;
}
